﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ArrayListLx
{
    class Program
    {
        static void Main(string[] args)
        {
            ArrayList list = new ArrayList() {"aaa","bbb","abc",123,456 };
            //查找集合中的元素
            int index = list.IndexOf("abc");
            if (index!=-1)
            {
                Console.WriteLine("集合中存在abc元素");
            }
            else
            {
                Console.WriteLine("集合中不存在abc元素");
            }
            Console.WriteLine();
            //集合中添加元素
            ArrayList newList = new ArrayList();
            for (int i=0;i<list.Count;i=i+2)
            {
                newList.Add(list[i]);
            }
            foreach (var i in newList)
            {
                Console.WriteLine(i);

            }
            ArrayList list1 = new ArrayList();
            list1.AddRange(list);
            foreach (var i in list1)
            {
                Console.WriteLine(i);

            }

            Console.WriteLine();

            //在指定位置插入元素
            ArrayList inserList = new ArrayList() { "A","B","C"};
            list.InsertRange(1,inserList);
            foreach (var i in list)
            {
                Console.WriteLine(i);
            }
            Console.WriteLine();
            list.Insert(1,"a");
            foreach (var i in list)
            {
                Console.WriteLine(i);
            }
            Console.WriteLine();
            inserList.Insert(1,"A"); 
            foreach (var i in inserList)
            {
                Console.WriteLine(i);
            }
            Console.WriteLine();
            
            //集合元素排序
            ArrayList list2 = new ArrayList() {"aaa","bbb","abc" };
            list2.Sort();
            foreach (var i in list2)
            {
                Console.WriteLine(i);
            }

            Console.ReadKey();
        }
    }
}
